package com.yh.csx.event.store.gateway.event;

import com.yh.csx.event.store.event.dto.req.EventReq;
import com.yh.csx.event.store.event.dto.resp.EventResp;
import com.yh.csx.event.store.gateway.event.dataobject.BizEventDo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface EventRepository extends JpaRepository<BizEventDo,String> {

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "INSERT IGNORE INTO biz_event " +
            "(id, topic, tag, event_id, location_code, event_type, project_id, " +
            "app_name, order_id, biz_id, biz_type, status, happen_time, event_body, remark, creator, updater) " +
            "VALUES(:#{#eventDo.id},:#{#eventDo.topic}, :#{#eventDo.tag}, :#{#eventDo.eventId}, :#{#eventDo.locationCode}, :#{#eventDo.eventType},:#{#eventDo.projectId}, " +
            ":#{#eventDo.appName}, :#{#eventDo.orderId}, :#{#eventDo.bizId}, :#{#eventDo.bizType}, :#{#eventDo.status}, :#{#eventDo.happenTime}," +
            ":#{#eventDo.eventBody} , :#{#eventDo.remark}, :#{#eventDo.creator}, 'sys') ")
    void mergeEvent(@Param("eventDo") BizEventDo eventDo);


}
